package com.tour.tour.controller;

import com.tour.tour.common.Response;
import com.tour.tour.dto.CommentDTO;
import com.tour.tour.entity.PostInfo;
import com.tour.tour.exception.UserStatusException;
import com.tour.tour.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 76004
 * @apiNote
 * @date 2023/4/25 9:27
 */
@RestController
@RequestMapping("/post")
@CrossOrigin
public class PostController {
    @Autowired
    private PostService postService;

    @PostMapping("/add-post")
    public Response<Void> addPost(@RequestBody PostInfo postInfo, HttpServletRequest httpServletRequest) throws UserStatusException {
        return postService.addPost(postInfo, httpServletRequest);
    }

    @GetMapping("/get-post-page")
    public Response<List<PostInfo>> selectPostInfoPage(Integer pageSize, Integer pageNum) {
        return postService.selectPostInfoPage(pageSize,pageNum);
    }

    @GetMapping("/get-page-by-username")
    public Response<List<PostInfo>> selectPostInfoByUsername(String username, Integer pageSize, Integer pageNum) {
        return postService.selectPostInfoByUsername(username,pageSize,pageNum);
    }

    @GetMapping("/get-by-id")
    public Response<PostInfo> selectPost(Long id) {
        return postService.selectPost(id);
    }

    @DeleteMapping("/delete")
    public Response<Void> deletePost(Long id) {
        return postService.deletePost(id);
    }

    @PutMapping("/update")
    public Response<Void> updatePost(PostInfo postInfo) {
        return postService.updatePost(postInfo);
    }

    @PostMapping("/comment")
    public Response<Void> comment(@RequestBody CommentDTO commentDTO, HttpServletRequest httpServletRequest) throws UserStatusException {
        return postService.comment(commentDTO, httpServletRequest);
    }
}
